package models

type orders struct {
	Order_id string `gorm:"colunmn:order_id"`
	Consumer_id int `gorm:"column:Consumer_id"`
	Goods_id string `gorm:"column:goods_id"`
	Order_date string `gorm:"column:order_date"`
	Trans_request string`gorm:"column:trans_request"`
	Is_available string `gorm:"column:is_available"`
	Trans_fare int `gorm:"column:trans_fare"`
}

func GetAllorders() (error, []orders, int64)  {
	var oredersdata []orders
	//page := goodsParam["page"].(int)
	//pageSize := goodsParam["limit"].(int)
	//searchText := goodsParam["searchText"].(string)
	var total int64
	err := db.Table("oreders").Order("order_id ASC").Count(&total).Find(&oredersdata).Error

	return err, oredersdata, total
}

func Addorders() (error, orders) {

	//a.BindJSON(&injurydata)
	//injurydata.Is_del = false
	//injurydata.Update_username = "系统管理员"
	//injurydata.Update_time = time.Now()
	ordersdata := orders{"5",3,"3","2020-6-19","无","false",100}
	err := db.Table("goods").Create(&ordersdata).Error
	return err, ordersdata
}

func Updateorders() (error, orders) {

	//a.BindJSON(&injurydata)
	//injurydata.Update_username = "系统管理员"
	//injurydata.Update_time = time.Now()
	ordersdata := orders{"5",3,"3","2020-6-19","无","false",100}
	err := db.Table("orders").Where("order_id = ?", ordersdata.Goods_id).Updates(&ordersdata).Error
	return err, ordersdata
}

func Delorders() error {
	id := "1"
	err := db.Table("orders").Where("order_id = ?", id).Delete(orders{}).Error
	return err
}
